package jp.co.sega.sonic_jump.monthly.sum;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.io.OutputStream;
import java.util.Calendar;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import jp.co.sega.sonic_jump.monthly.sum.PlatformStandard.Define;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.Manifest;
import android.content.pm.PackageManager;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.media.MediaPlayer;
import android.util.DisplayMetrics;
import android.webkit.ValueCallback;
import android.widget.Toast;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.IOException;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.os.Environment;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;

public class Shell extends Activity {
    private static final int DIALOG_CERTIFICATION_MESSAGE = 200;
    private static final int DIALOG_ERROR_MESSAGE = 400;
    private static final int DIALOG_ERROR_NOT_WEB_TO_MESSAGE = 600;
    private static final int DIALOG_ERROR_WEB_TO_MESSAGE = 500;
    private static final int DIALOG_FINISH_MESSAGE = 100;
    private static final int DIALOG_OK_MESSAGE = 300;
    private static final int HTML_APP_START = 2;
    private static final int HTML_ERROR = 1;
    private static final int HTML_HANDLER_START = 3;
    private static final int HTML_MONTHLY = 0;
    private static boolean MONTHLY_CHECK = true;
    public static Shell sInstance = null;
    public final String ANDROID_URL = "http://puyosega-android.segamobile.jp";
    public String appid = "sonic_jump";
    /* access modifiers changed from: private */
    public Game_Draw canvas = null;
    /* access modifiers changed from: private */
    public int day = 0;
    private String devid = null;
    /* access modifiers changed from: private */
    public String error_code = Define.PACKAGE_ID;
    private String esubid = null;
    /* access modifiers changed from: private */
    public int hour = 0;
    /* access modifiers changed from: private */
    public Handler mHandler = new Handler();
    /* access modifiers changed from: private */
    public int minute = 0;
    /* access modifiers changed from: private */
    public int month = 0;
    public boolean monthly_check_flag = false;
    public boolean Resume = false;
    public int monthly_mode = 0;
    /* access modifiers changed from: private */
    public String[] msg = null;
    /* access modifiers changed from: private */
    public ProgressDialog progressDialog = null;
    /* access modifiers changed from: private */
    public int second = 0;
    private boolean suspend_monthly_check_flag = false;
    private boolean suspend_progress_flag = false;
    private String ver = "100";
    Vibrator vibrator;
    private WebSettings webSettings = null;
    /* access modifiers changed from: private */
    public boolean web_error_flag = false;
    /* access modifiers changed from: private */
    public boolean web_progress_flag = false;
    private WebView webview = null;
    /* access modifiers changed from: private */
    public int year = 0;
    
    public ValueCallback<Uri> mUploadMessage;         // Android < 5.0
    public ValueCallback<Uri[]> mFilePathCallback;    // Android >= 5.0
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (mFilePathCallback == null) return;
                Uri[] results = null;
                if (resultCode == RESULT_OK) {
                    if (data != null) {
                        String dataString = data.getDataString();
                        if (dataString != null) {
                            results = new Uri[]{ Uri.parse(dataString) };
                        }
                    }
                }
                mFilePathCallback.onReceiveValue(results);
                mFilePathCallback = null;
            } else {
                if (mUploadMessage == null) return;
                Uri result = null;
                if (resultCode == RESULT_OK) {
                    if (data != null) {
                        result = data.getData();
                    }
                }
                mUploadMessage.onReceiveValue(result);
                mUploadMessage = null;
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }

        if (resultCode != RESULT_OK || data == null || data.getData() == null) {
            Toast.makeText(Shell.sInstance, "Operation canceled or file retrieval failed", Toast.LENGTH_SHORT).show();
            return;
        }

        Uri uri = data.getData();

        if (requestCode == Shell.sInstance.getCanvas().getEditor().PICK_MAP_FILE) {
            Shell.sInstance.getCanvas().getEditor().roomindex = new int[21];
            Shell.sInstance.getCanvas().getEditor().currentFileUri = uri;
            String fileName = Shell.sInstance.getCanvas().getEditor().getFileNameFromUri(Shell.sInstance.getCanvas().getEditor().currentFileUri);
            if (fileName != null && fileName.toLowerCase().equals("fs")) {
            Shell.sInstance.getCanvas().getEditor().s2005 = true;
            //selectMapFile();
            Pattern pattern = Pattern.compile("\\d+");
            Matcher matcher = pattern.matcher(fileName);
            if (matcher.find()) {
            Shell.sInstance.getCanvas().getEditor().currentmap = Integer.parseInt(matcher.group());
            }
            Shell.sInstance.getCanvas().getEditor().bits16 = false;
            Shell.sInstance.getCanvas().getEditor().loadMapFile2(uri);
            //selectRoomButton.setVisibility(View.GONE);
            Shell.sInstance.getCanvas().getEditor().showEditor();
            return;
            }
            Shell.sInstance.getCanvas().getEditor().s2005 = false;
            //selectRoomButton.setVisibility(View.VISIBLE);
    if (fileName != null && fileName.toLowerCase().endsWith(".txt")) {
        Shell.sInstance.getCanvas().getEditor().loadTxtToRealmap(Shell.sInstance.getCanvas().getEditor().currentFileUri);
        } else {
            InputStream is = null;
            try {
                is = getContentResolver().openInputStream(uri);
                if (is == null) {
                    Toast.makeText(Shell.sInstance, "Could not open file", Toast.LENGTH_SHORT).show();
                    return;
                }
                Shell.sInstance.getCanvas().getEditor().realmap = Shell.sInstance.getCanvas().getEditor().readFully(is);
                Shell.sInstance.getCanvas().getEditor().loadMapFile2(uri);
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(Shell.sInstance, "Error loading file", Toast.LENGTH_SHORT).show();
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            }
        } /*else if (requestCode == SAVE_MAP_FILE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                currentFileUri = uri;
                saveMapFile2();
            } else {
                Toast.makeText(Shell.sInstance, "File saving not supported on Shell.sInstance version of Android", Toast.LENGTH_LONG).show();
            }
        }*/ else if (requestCode == Shell.sInstance.getCanvas().getEditor().SAVE_MAP_FILE && resultCode == RESULT_OK) {
        if (data != null) {
        
            final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            getContentResolver().takePersistableUriPermission(uri, takeFlags);
            
            String path = uri.getPath();

            if (path != null && path.endsWith(".txt")) {
                Shell.sInstance.getCanvas().getEditor().saveMapFile2(uri, true);
            } else {
                Shell.sInstance.getCanvas().getEditor().saveMapFile2(uri, false);
            }
        }
    } else if (requestCode == Shell.sInstance.getCanvas().getEditor().REQUEST_CODE_OPEN_DOCUMENT_TREE && resultCode == RESULT_OK) {
        Uri treeUri = data.getData();

        // Permissão persistente
        final int takeFlags = data.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        getContentResolver().takePersistableUriPermission(treeUri, takeFlags);

        // Salva o URI em SharedPreferences
        Shell.sInstance.getCanvas().getEditor().prefs = PreferenceManager.getDefaultSharedPreferences(Shell.sInstance);
        Shell.sInstance.getCanvas().getEditor().prefs.edit().putString("tree_uri", treeUri.toString()).apply();
    }
    }
    
    @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == 200) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permissão concedida
            Shell.sInstance.getCanvas().getEditor().selectMapFile();
        } else {
            Toast.makeText(this, "Write permission is required to save files", Toast.LENGTH_LONG).show();
        }
    }
}
    
    public Game_Draw getCanvas() {
    return this.canvas;
    }

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT <= 28) {
        if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
    }
}
       if (Build.VERSION.SDK_INT >= 33) {
        if (this.checkSelfPermission("android.permission.READ_MEDIA_DOCUMENTS") != PackageManager.PERMISSION_GRANTED) {
        this.requestPermissions(new String[]{"android.permission.READ_MEDIA_DOCUMENTS"}, 2);
    }
}
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
       if (!Environment.isExternalStorageManager()) {
        Toast.makeText(this, "Allow the app to access files", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
        startActivity(intent);
    }
    while (!Environment.isExternalStorageManager()) {
    }
}

        getWindow().addFlags(Text.STORY_56);
        getWindow().addFlags(Graphics.TOP);
        requestWindowFeature(1);
        if (Build.VERSION.SDK_INT >= 28) {
            getWindow().setFlags(Graphics.HCENTER, Graphics.HCENTER);
            getWindow().getAttributes().layoutInDisplayCutoutMode = 0;
        }
        if (Build.VERSION.SDK_INT >= 19) {
            getWindow().setFlags(Graphics.HCENTER, Graphics.HCENTER);
            getWindow().getDecorView().setSystemUiVisibility(4098);
        }
        sInstance = this;
        /*if (!MONTHLY_CHECK) {
            exe(2);
        } else if (this.esubid == null) {
            this.error_code = "SIM ERROR";
            exe(1);
        } else if (this.devid == null) {
            this.error_code = "DEV ERROR";
            exe(1);
        } else {*/
            //byte[] sData = read_data("esubid");
            //byte[] dData = read_data("devid");
            /*if (sData == null && dData == null) {
                exe(0);
                return;
            }*/
            String _subid = Define.PACKAGE_ID;
            String _devid = Define.PACKAGE_ID;
            boolean check = true;
            /*if (sData != null) {
                _subid = new String(sData);
            }
            if (dData != null) {
                _devid = new String(dData);
            }
            if (_subid.equals(Define.PACKAGE_ID) || !_subid.equals(this.esubid)) {
                check = false;
            }
            if (_devid.equals(Define.PACKAGE_ID) || !_devid.equals(this.devid)) {
                check = false;
            }*/
            exe(0);
            /*if (!check) {
                exe(0);
            } else if (monthly_check()) {
                exe(0);
            } else {
                exe(2);
            }*/
        //}
    }

    public void ProgressDialogStart() {
        this.suspend_progress_flag = true;
        new Thread(new Runnable() {
            public void run() {
                Shell.this.mHandler.post(new Runnable() {
                    public void run() {
                        Shell.this.progressDialog = new ProgressDialog(Shell.sInstance);
                        if (Shell.this.progressDialog != null) {
                            Shell.this.progressDialog.setProgressStyle(0);
                            Shell.this.progressDialog.setMessage("通信中…");
                            Shell.this.progressDialog.setIndeterminate(false);
                            Shell.this.progressDialog.setCancelable(false);
                            Shell.this.progressDialog.show();
                        }
                    }
                });
            }
        }).start();
    }

    public void ProgressDialogEnd() {
        if (this.suspend_progress_flag) {
            this.suspend_progress_flag = false;
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            if (Shell.this.progressDialog != null) {
                                Shell.this.progressDialog.dismiss();
                                Shell.this.progressDialog = null;
                            }
                        }
                    });
                }
            }).start();
        }
    }

    private boolean monthly_check() {
        boolean certification = false;
        Calendar cal1 = Calendar.getInstance();
        this.year = cal1.get(1);
        this.month = cal1.get(2) + 1;
        this.day = cal1.get(5);
        this.hour = cal1.get(11);
        this.minute = cal1.get(12);
        this.second = cal1.get(13);
        byte[] bYear = read_data("bYear");
        byte[] bMonth = read_data("bMonth");
        byte[] bDay = read_data("bDay");
        byte[] bHour = read_data("bHour");
        byte[] bMinute = read_data("bMinute");
        byte[] bSecond = read_data("bSecond");
        if (bYear == null || bMonth == null || bDay == null || bHour == null || bMinute == null || bSecond == null) {
            return true;
        }
        String str = new String(bYear);
        String str2 = new String(bMonth);
        String str3 = new String(bDay);
        String str4 = new String(bHour);
        String str5 = new String(bMinute);
        String str6 = new String(bSecond);
        Calendar now = Calendar.getInstance();
        now.set(this.year, this.month, this.day, this.hour, this.minute, this.second);
        Calendar old = Calendar.getInstance();
        old.set(atoi(str), atoi(str2), atoi(str3), atoi(str4), atoi(str5), atoi(str6));
        if (!now.after(old)) {
            certification = true;
        }
        if (!(String.valueOf(this.year) + this.month).equals(String.valueOf(str) + str2)) {
            return true;
        }
        return certification;
    }

    public void monthly_check_dialog() {
        this.monthly_check_flag = true;
        this.suspend_monthly_check_flag = false;
        try {
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            Shell.this.showDialog(200);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
        }
    }

    public void network_ok_dialog() {
        try {
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            Shell.this.showDialog(Shell.DIALOG_OK_MESSAGE);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
        }
    }

    public void network_error_dialog() {
        try {
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            Shell.this.showDialog(Shell.DIALOG_ERROR_MESSAGE);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
        }
    }

    public void network_error_web_to_dialog(String[] msg2) {
        this.msg = msg2;
        try {
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            Shell.this.showDialog(Shell.DIALOG_ERROR_WEB_TO_MESSAGE);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
        }
    }

    public void network_error_not_web_to_dialog(String[] msg2) {
        this.msg = msg2;
        try {
            new Thread(new Runnable() {
                public void run() {
                    Shell.this.mHandler.post(new Runnable() {
                        public void run() {
                            Shell.this.showDialog(Shell.DIALOG_ERROR_NOT_WEB_TO_MESSAGE);
                        }
                    });
                }
            }).start();
        } catch (Exception e) {
        }
    }

    public void onResume() {
        super.onResume();
        Editor editor = getCanvas().editor;
        if (editor != null) this.registerReceiver(editor.playerStateReceiver, new IntentFilter("PLAYER_STATE_CHANGED"));
        /*if (MONTHLY_CHECK && monthly_check() && this.suspend_monthly_check_flag && this.canvas != null) {
            monthly_check_dialog();
        }*/
        if (this.canvas != null) {
        
        }
        this.Resume = true;
        this.suspend_monthly_check_flag = false;
    }

    public void onPause() {
        super.onPause();
        Editor editor = getCanvas().editor;
        if (editor != null) this.unregisterReceiver(editor.playerStateReceiver);
        /*if (MONTHLY_CHECK) {
            ProgressDialogEnd();
            this.monthly_mode = 0;
            this.suspend_monthly_check_flag = true;
            if (this.web_progress_flag) {
                this.web_progress_flag = false;
                if (this.progressDialog != null) {
                    this.progressDialog.dismiss();
                    this.progressDialog = null;
                }
                this.error_code = "SUSPEND ERROR";
                exe(1);
            }
        }*/
        if (this.canvas != null) {
            this.canvas.reset();
        }
        this.Resume = false;
    }

    public void exit() {
        /*super.finish();
        System.exit(0);*/
    }

    public void onStart() {
        super.onStart();
    }

    public void onStop() {
        super.onStop();
    }

    public void onDestroy() {
        super.onDestroy();
        Editor editor = getCanvas().editor;
        if (editor != null) this.unregisterReceiver(editor.playerStateReceiver);
        stopService(new Intent(this, Editor.PlayerService.class));
        /*if (this.canvas != null) {
            this.canvas.b_Exit = true;
        }
        DeviceSound.releaseAll();
        exit();*/
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (this.canvas != null) {
                return this.canvas.onKeyDown(keyCode, event);
            }
            return true;
        }

    public void Vibrate(int t) {
        if (1 != 0) {
            this.vibrator = (Vibrator) getSystemService("vibrator");
            this.vibrator.vibrate((long) t);
        }
    }

    /* access modifiers changed from: protected */
    public Dialog onCreateDialog(int id) {
    return null;
    }

    /* access modifiers changed from: private */
    public void webTo(String url) {
        try {
            startActivityForResult(new Intent("android.intent.action.VIEW", Uri.parse(url)), 0);
            try {
                Thread.sleep(100);
            } catch (Exception e) {
            }
            exit();
        } catch (Exception e2) {
        }
    }

    /* access modifiers changed from: private */
    public void write_data(String p_fileName, byte[] p_data) {
        OutputStream out = null;
        try {
            out = openFileOutput(p_fileName, 0);
            out.write(p_data, 0, p_data.length);
            out.close();
        } catch (Exception e) {
            if (out != null) {
                try {
                    out.close();
                } catch (Exception e2) {
                }
            }
        }
    }

    private byte[] read_data(String p_fileName) {
        byte[] w = new byte[10240];
        InputStream in = null;
        ByteArrayOutputStream out = null;
        try {
            in = openFileInput(p_fileName);
            ByteArrayOutputStream out2 = new ByteArrayOutputStream();
            while (true) {
                try {
                    int size = in.read(w);
                    if (size > 0) {
                        out2.write(w, 0, size);
                    } else {
                        byte[] ret = out2.toByteArray();
                        out2.close();
                        in.close();
                        return ret;
                    }
                } catch (Exception e) {
                    out = out2;
                    if (out != null) {
                        try {
                            out.close();
                        } catch (Exception e2) {
                        }
                    }
                    if (in != null) {
                        try {
                            in.close();
                        } catch (Exception e3) {
                        }
                    }
                    return new byte[0];
                }
            }
        } catch (Exception e4) {
        return new byte[0];
        }
    }

    private int atoi(String string) {
        try {
            return Integer.parseInt(string);
        } catch (Exception e) {
            return 0;
        }
    }

    /* access modifiers changed from: private */
    public void exe(int mode) {
        if (mode == 0 || mode == 1) {
            gameStart();
        } else if (mode == 3) {
            gameStart();
        } else if (mode == 2) {
            gameStart();
        }
    }

    /* access modifiers changed from: private */
    public void gameStart() {
        write_data("bYear", new StringBuilder(String.valueOf(this.year)).toString().getBytes());
        write_data("bMonth", new StringBuilder(String.valueOf(this.month)).toString().getBytes());
        write_data("bDay", new StringBuilder(String.valueOf(this.day)).toString().getBytes());
        write_data("bHour", new StringBuilder(String.valueOf(this.hour)).toString().getBytes());
        write_data("bMinute", new StringBuilder(String.valueOf(this.minute)).toString().getBytes());
        write_data("bSecond", new StringBuilder(String.valueOf(this.second)).toString().getBytes());
        this.canvas = new Game_Draw();
        setContentView(this.canvas);
        try {
            /*SensorManager sensorMgr = (SensorManager) getBaseContext().getSystemService("sensor");
            sensorMgr.registerListener(new SensorEventListener() {
                public void onSensorChanged(SensorEvent e) {
                    Shell.this.canvas.sensor_x = e.values[0];
                }

                public void onAccuracyChanged(Sensor s, int accuracy) {
                }
            }, sensorMgr.getDefaultSensor(1), 1);*/
            
            SensorManager sensorMgr = (SensorManager) getBaseContext().getSystemService(Context.SENSOR_SERVICE);
if (sensorMgr != null) {
    Sensor accel = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (accel != null) {
        sensorMgr.registerListener(new SensorEventListener() {
            @Override
            public void onSensorChanged(SensorEvent e) {
                Shell.this.canvas.sensor_x = e.values[0];
            }

            @Override
            public void onAccuracyChanged(Sensor s, int accuracy) {
            }
        }, accel, SensorManager.SENSOR_DELAY_NORMAL);
    }
}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getEncryptionSubID() {
        String before_subid = this.esubid;
        return toHexString(encrypt(before_subid.getBytes(), "UMAS3_SMARTPHONE".getBytes()));
    }

    private String getHTML(int mode) {
        if (mode == 0) {
            return "<html><head><meta http-equiv=\"refresh\" content=\"0;URL=http://puyosega-android.segamobile.jp/ninshou/news.jsp?esubid=" + getEncryptionSubID() + "&devid=" + this.devid + "&appid=" + this.appid + "&ver=" + this.ver + "\">" + "</head>" + "<body>" + "</body>" + "</html>";
        }
        if (mode != 1) {
            return Define.PACKAGE_ID;
        }
        String html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html lang=\"ja\">\t<head>\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=shift_jis\">\t\t<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\t\t<meta name=\"viewport\" content=\"initial-scale=1.0;\">\t\t<script type=\"text/javascript\">\t\t\tfunction android_exit() { android.exit(); }\t\t</script>\t\t<title>\t\t\tE-7\t\t</title>\t</head>\t\t<body bgcolor=\"#ffffff\" text=\"#000000\" topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\"><div style=\"width: 100%; background:#154f98\" align=\"right\"><img src=\"img/migiue.gif\" alt=\"ヘッダー\"><br></div><div style=\"width: 100%; background:#f7e908\" align=\"center\"><img src=\"img/error.gif\" alt=\"通信に失敗しました\"><br></div><table width=\"85%\" align=\"center\" bgcolor=\"#FFFFFF\" border=\"0\">    <tr>    <td bgcolor=\"#ffffff\"><br>[<!--エラー番号--> ERROR TYPE:" + this.error_code + "]<br>" + "<br>" + "お手数ですが、一度アプリを終了し、再度起動してください。<br>" + "<br>" + "<div align=\"center\">" + "<input type=\"image\" src=\"img/end.gif\" alt=\"終了\" onClick=\"android_exit()\"><br>" + "</div>" + "<br>" + "    </td>" + "  </tr>" + "</table>" + "<div style=\"width: 100%; background:#154f98\" align=\"left\">" + "<img src=\"img/hidarishita.gif\" alt=\"フッダー\"><br>" + "</div>" + "<div style=\"width: 100%; background:#2166bc\" align=\"center\">" + "<img src=\"img/sega_logo.gif\" alt=\"セガロゴ\"><br>" + "</div>" + "\t</body>" + "</html>";
        this.web_error_flag = true;
        return html;
    }
public byte[] http_connect(String path) throws Exception {
        Exception e;
        byte[] w = new byte[1024000];
        HttpURLConnection c = null;
        InputStream in = null;
        ByteArrayOutputStream out = null;
        try {
            URL url = new URL(path);
            c = (HttpURLConnection) url.openConnection();
            c.setRequestMethod("GET");
            c.connect();
            in = c.getInputStream();
            ByteArrayOutputStream out2 = new ByteArrayOutputStream();
            while (true) {
                try {
                    int size = in.read(w);
                    if (size > 0) {
                        out2.write(w, 0, size);
                    } else {
                        out2.close();
                        in.close();
                        c.disconnect();
                        return out2.toByteArray();
                    }
                } catch (Exception e2) {
                    e = e2;
                    out = out2;
                    if (c != null) {
                        try {
                            c.disconnect();
                        } catch (Exception e3) {
                        }
                    }
                    if (in != null) {
                        try {
                            in.close();
                        } catch (Exception e4) {
                        }
                    }
                    if (out != null) {
                        try {
                            out.close();
                            throw e;
                        } catch (Exception e5) {
                            throw e;
                        }
                    }
                    throw e;
                }
            }
        } catch (Exception e6) {
            e = e6;
            return new byte[0];
        }
    }
    private byte[] encrypt(byte[] data, byte[] secret_key) {
        try {
            SecretKeySpec sKey = new SecretKeySpec(secret_key, "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(1, sKey, new IvParameterSpec("UMAS3_ANDROID_IV".getBytes()));
            return cipher.doFinal(data);
        } catch (Exception e) {
            return null;
        }
    }

    private String toHexString(byte[] _byte) {
        StringBuffer hexString = new StringBuffer();
        for (byte b : _byte) {
            String plainText = Integer.toHexString(b & 255);
            if (plainText.length() < 2) {
                plainText = "0" + plainText;
            }
            hexString.append(plainText);
        }
        return new String(hexString);
    }

    class CustomWebViewClient extends WebViewClient {
        private Activity activity;

        public CustomWebViewClient(Activity activity2) {
            this.activity = activity2;
            Shell.this.web_progress_flag = false;
        }

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            super.shouldOverrideUrlLoading(view, url);
            view.loadUrl(url);
            return true;
        }

        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (!Shell.this.web_error_flag) {
                super.onPageStarted(view, url, favicon);
                if (!Shell.this.web_progress_flag) {
                    Shell.this.web_progress_flag = true;
                    Shell.this.progressDialog = new ProgressDialog(this.activity);
                    Shell.this.progressDialog.setProgressStyle(0);
                    Shell.this.progressDialog.setMessage("通信中…");
                    Shell.this.progressDialog.setIndeterminate(false);
                    Shell.this.progressDialog.setCancelable(false);
                    Shell.this.progressDialog.show();
                }
            }
        }

        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (Shell.this.web_progress_flag) {
                Shell.this.web_progress_flag = false;
                if (Shell.this.progressDialog != null) {
                    Shell.this.progressDialog.dismiss();
                    Shell.this.progressDialog = null;
                }
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            Shell.this.error_code = new StringBuilder(String.valueOf(errorCode)).toString();
            error();
        }

        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslErrorHandler error) {
            Shell.this.error_code = "SSL ERROR";
            error();
        }

        private void error() {
            if (Shell.this.web_progress_flag) {
                Shell.this.web_progress_flag = false;
                if (Shell.this.progressDialog != null) {
                    Shell.this.progressDialog.dismiss();
                    Shell.this.progressDialog = null;
                }
            }
            Shell.this.exe(1);
        }
    }

    class JavaScript {
        private Shell activity;

        public JavaScript(Shell activity2) {
            this.activity = activity2;
        }

        public void exit() {
            this.activity.finish();
            System.exit(0);
        }

        public void start() {
            this.activity.exe(3);
        }
    }

    /* access modifiers changed from: protected */
    public void onPrepareDialog(int id, Dialog dialog) {
        if (id == DIALOG_ERROR_NOT_WEB_TO_MESSAGE) {
            String[] a = this.msg[1].split("/");
            String text = Define.PACKAGE_ID;
            for (int i = 0; i < a.length; i++) {
                text = String.valueOf(text) + a[i] + "\n";
            }
            ((AlertDialog) dialog).setTitle("code : " + this.msg[0]);
            ((AlertDialog) dialog).setMessage(text);
        }
    }
}
